cmake_minimum_required(VERSION 3.10)
set(prj_name "cu-bridge")
if (NOT DEFINED ENV{MACA_PATH})
    message(FATAL_ERROR "env MACA_PATH NOT set!")
endif()
set(MACA_PATH $ENV{MACA_PATH})

set(LIBRARY_NAME ${prj_name})
set(DEST_DIR "./")
set(LIB_DEST_DIR "${MACA_PATH}/lib")

set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(PACKAGE_GENERATOR "DEB" CACHE STRING "default custom package types, DEB or RPM")
set(CMAKE_TARGET_ARCH "x86_64" CACHE STRING "default target arch, x86_64 or aarch64")

message(STATUS "prj_name:${prj_name}")
message(STATUS "DEST_DIR:${DEST_DIR}")
message(STATUS "MACA_PATH=${MACA_PATH}")
message(STATUS "PACKAGE_GENERATOR=${PACKAGE_GENERATOR}")
message(STATUS "CMAKE_TARGET_ARCH=${CMAKE_TARGET_ARCH}")

add_subdirectory(src)

install(DIRECTORY bin DESTINATION ${DEST_DIR} USE_SOURCE_PERMISSIONS)
install(DIRECTORY include
        DESTINATION ${DEST_DIR}
        USE_SOURCE_PERMISSIONS)
add_custom_target(softlink ALL)
add_custom_command(
    TARGET softlink
    COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/include/soft-link
    COMMAND ln -snf ${MACA_PATH}/include/cutlass ${CMAKE_INSTALL_PREFIX}/include/soft-link/cutlass
    COMMAND ln -snf ${MACA_PATH}/include/thrust ${CMAKE_INSTALL_PREFIX}/include/soft-link/thrust)

install(DIRECTORY cmake_module DESTINATION ${DEST_DIR} USE_SOURCE_PERMISSIONS)
install(PROGRAMS tools_src/gomxcc/bin/${CMAKE_TARGET_ARCH}/gomxccbin DESTINATION ${DEST_DIR}/bin)

install(DIRECTORY tools
        DESTINATION ${DEST_DIR}
        USE_SOURCE_PERMISSIONS)